package com.cloud.bc.service.impl;

import com.cloud.bc.model.entity.BcWechatemplateMessages;
import com.cloud.bc.mapper.BcWechatemplateMessagesMapper;
import com.cloud.bc.service.BcWechatemplateMessagesService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 微信（模版消息）
 *
 * @author douhaichao code generator
 * @date 2021-02-05 11:12:07
 */
@Service
@AllArgsConstructor
public class BcWechatemplateMessagesServiceImpl extends ServiceImpl<BcWechatemplateMessagesMapper, BcWechatemplateMessages> implements BcWechatemplateMessagesService {

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */
    @Override
    public BcWechatemplateMessages selectOne(BcWechatemplateMessages req) {
        QueryWrapper queryWrapper = new QueryWrapper<BcWechatemplateMessages>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<BcWechatemplateMessages> selectAll(BcWechatemplateMessages req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<BcWechatemplateMessages> selectPage(Page page, BcWechatemplateMessages req) {
        IPage<BcWechatemplateMessages> list = baseMapper.selectPage(
                page,
                new QueryWrapper<BcWechatemplateMessages>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<BcWechatemplateMessages> selectPageByLike(Page page, BcWechatemplateMessages req) {
        QueryWrapper queryWrapper = new QueryWrapper();

        if (null != req.getId()) {
            queryWrapper.eq("id", req.getId());
        }

        if (!StrUtil.isEmpty(req.getAlias())) {
            queryWrapper.like("alias", req.getAlias());
        }

        if (!StrUtil.isEmpty(req.getName())) {
            queryWrapper.like("name", req.getName());
        }

        if (!StrUtil.isEmpty(req.getTemplateId())) {
            queryWrapper.like("template_id", req.getTemplateId());
        }

        if (!StrUtil.isEmpty(req.getUrl())) {
            queryWrapper.like("url", req.getUrl());
        }

        if (!StrUtil.isEmpty(req.getMiniprogram())) {
            queryWrapper.like("miniprogram", req.getMiniprogram());
        }

        if (!StrUtil.isEmpty(req.getColor())) {
            queryWrapper.like("color", req.getColor());
        }

        if (!StrUtil.isEmpty(req.getData())) {
            queryWrapper.like("data", req.getData());
        }

        if (!StrUtil.isEmpty(req.getParams())) {
            queryWrapper.like("params", req.getParams());
        }

        if (!StrUtil.isEmpty(req.getModule())) {
            queryWrapper.like("module", req.getModule());
        }

        if (null != req.getIsSwitch()) {
            queryWrapper.eq("is_switch", req.getIsSwitch());
        }
        IPage<BcWechatemplateMessages> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(BcWechatemplateMessages req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }
}
